// Copyright 2022 a.o.smith ALL Rights Reserved
package com.liuxinlong.modules.chimi.controller;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import com.liuxinlong.modules.chimi.controller.request.UpdateBarLuckDetailReq;
import com.liuxinlong.modules.chimi.service.BarLuckDetailService;
import com.liuxinlong.modules.common.controller.request.QueryBaseReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 论坛抽奖配置管理控制层
 * 
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2022-08-08
 */
@RestController
@RequestMapping("/luck-detail")
public class BarLuckDetailController {

	@Autowired
	private BarLuckDetailService barLuckDetailService;

	/**
	 * 分页查询抽奖奖品配置信息
	 * 
	 * @param req 请求信息
	 * @return 抽奖奖品配置信息列表
	 */
	@PostMapping("award/page")
	public BaseResp pageLuckAwardList(@RequestBody QueryBaseReq req) {
		Map<String,Object> queryParam = new HashMap<>();
		queryParam.put("startNum",req.getStartNum());
		queryParam.put("pageSize",req.getPageSize());
		queryParam.put("luckId",req.getId());
		List<Map<String,Object>> dataList = barLuckDetailService.pageLuckAwardList(queryParam);
		int total = barLuckDetailService.getLuckAwardCount(queryParam);
		BaseResp resp = new BaseResp();
		resp.setDataList(dataList);
		resp.setTotalNum(total);
		resp.setRetMessage("分页查询抽奖奖品信息成功");
		return resp;
	}

	/**
	 * 修改抽奖奖品信息
	 * 
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("award/update")
	@LogAnnotation(value ="修改抽奖奖品信息",business = LogBusinessConstants.BAR_LUCK_DETAIL,operateType = LogOperateConstants.OPERATE_MODIFY)
	public BaseResp updateLuckAward(@RequestBody UpdateBarLuckDetailReq req) {
		barLuckDetailService.updateLuckAward(req.getId(),req.getAwardList());
		BaseResp resp = new BaseResp();
		resp.setRetMessage("修改抽奖奖品信息成功");
		return resp;
	}

	/**
	 * 分页查询抽奖受众配置信息
	 *
	 * @param req 请求信息
	 * @return 抽奖受众配置信息列表
	 */
	@PostMapping("audience/page")
	public BaseResp pageLuckAudienceList(@RequestBody QueryBaseReq req) {
		Map<String,Object> queryParam = new HashMap<>();
		queryParam.put("startNum",req.getStartNum());
		queryParam.put("pageSize",1000);
		queryParam.put("luckId",req.getId());
		List<Map<String,Object>> dataList = barLuckDetailService.pageLuckAudienceList(queryParam);
		int total = barLuckDetailService.getLuckAudienceCount(queryParam);
		BaseResp resp = new BaseResp();
		resp.setDataList(dataList);
		resp.setTotalNum(total);
		resp.setRetMessage("分页查询抽奖受众信息成功");
		return resp;
	}

	/**
	 * 修改抽奖受众信息
	 *
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("audience/update")
	@LogAnnotation(value ="修改抽奖受众信息",business = LogBusinessConstants.BAR_LUCK_DETAIL,operateType = LogOperateConstants.OPERATE_MODIFY)
	public BaseResp updateLuck(@RequestBody UpdateBarLuckDetailReq req) {
		barLuckDetailService.updateLuckAudience(req.getId(),req.getAudienceList());
		BaseResp resp = new BaseResp();
		resp.setRetMessage("修改抽奖受众信息成功");
		return resp;
	}

}
